package com.jt.controller;

import com.jt.pojo.User;
import org.omg.CORBA.UserException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

@Controller
@ResponseBody
@CrossOrigin
@RequestMapping("/axios")
public class UserController {
    @RequestMapping("/hello")
    public String hello() {

        return "你好,SpringMVC";
    }

    @RequestMapping("/dog")
    public String dog() {

        return "小狗汪汪汪";
    }

    @RequestMapping("/cat")
    public String cat() {

        return "小猫喵喵喵";
    }

    @RequestMapping("/findUserByNA")
    public String findUserByNA(String name,int age){

        return "数据正确:"+name+":"+age;
    }


    @RequestMapping("/findUserByNA2")
    public String findUserByNA2(User user){

        return "数据正确:"+user.toString();
    }

    @RequestMapping("/hobby")
    public String hobby(String[] hobby){

        return Arrays.toString(hobby);
    }

    @RequestMapping("/findUser/{name}/{age}/{sex}")
    public String findUser(
           @PathVariable String name,
           @PathVariable int age,
           @PathVariable String sex
    ){
        return name+":"+age+":"+sex;
    }

    @RequestMapping("/findUser1/{id}/{name}/{age}/{sex}")
    public String findUser1(User user){

        return user.toString();
    }

    @RequestMapping("/findJson")
    //@ResponseBody

    public User findJson(User user){
        user.setId(10);
        user.setAge(100);
        user.setSex("男");
        user.setName("滚你妈的");
        return user;
    }


//@RequestMapping(value="/saveUser",method = RequestMethod.POST)
    @PostMapping("/saveUser")
    public String saveUser(@RequestBody User user){
        return "新增用户成功";
    }
@PutMapping("/updateUser")
    public String updateUser(@RequestBody User user){
        return "修改成功";
}
@DeleteMapping("/delite")
    public String delite(User user){
        return "删除成功";
}
}
